﻿//using System;
//using System.Configuration;
//using System.Data;
//using System.Data.SqlClient;
//using MySql.Data.MySqlClient;
//using TCL.EO;
//using TCL.FUNC;

//namespace TCL.DB
//{
//    public class MySqlDataProvider
//    {
//        #region "Properties"
//        public virtual Boolean bWriteLog { get; set; }
//        public virtual String sConnectionStrings { get; set; }
//        #endregion

//        #region DB Access Functions
//        protected void SetConnection(ref MySqlCommand cmdMySql)
//        {
//            MySqlConnection connMySql = new MySqlConnection(ConfigurationManager.ConnectionStrings[sConnectionStrings].ConnectionString);
//            if (connMySql.State != ConnectionState.Open)
//            {
//                connMySql.Open();
//            }
//            cmdMySql.Connection = connMySql;
//        }

//        protected void Convert_SqlCommand_MySqlCommand(SqlCommand cmdSql, ref MySqlCommand cmdMySql)
//        {
//            cmdMySql.CommandText = cmdSql.CommandText;
//            cmdMySql.CommandType = cmdSql.CommandType;
//            foreach (SqlParameter item in cmdSql.Parameters)
//            {
//                cmdMySql.Parameters.Add(new MySqlParameter(item.ParameterName, item.Value));
//            }
//            SetConnection(ref cmdMySql);
//        }

//        public DataSet GetDataSet(SqlCommand cmdSql)
//        {
//            MySqlCommand cmdMySql = new MySqlCommand();
//            LogDBEO objLog = new LogDBEO(cmdSql, sConnectionStrings, ConstEx.Log_iType.DATABASE_SELECT);
//            try
//            {
//                Convert_SqlCommand_MySqlCommand(cmdSql, ref cmdMySql);
//                using (DataSet ds = new DataSet())
//                {
//                    using (MySqlDataAdapter da = new MySqlDataAdapter())
//                    {
//                        da.SelectCommand = cmdMySql;
//                        da.Fill(ds);
//                        objLog.bStatus = true;
//                        return ds;
//                    }
//                }
//            }
//            finally
//            {
//                cmdMySql.Connection.Close();
//                cmdMySql.Dispose();
//                if (bWriteLog)
//                    (new Logs()).WriteLogDB(objLog);
//            }
//        }

//        public DataTable GetDataTable(SqlCommand cmdSql)
//        {
//            return GetDataSet(cmdSql).Tables[0];
//        }

//        public MySqlDataReader GetReadOnlyData(SqlCommand cmdSql)
//        {
//            MySqlCommand cmdMySql = new MySqlCommand();
//            LogDBEO objLog = new LogDBEO(cmdSql, sConnectionStrings, ConstEx.Log_iType.DATABASE_OTHER);
//            try
//            {
//                Convert_SqlCommand_MySqlCommand(cmdSql, ref cmdMySql);
//                objLog.bStatus = true;
//                return cmdMySql.ExecuteReader();
//            }
//            finally
//            {
//                cmdMySql.Connection.Close();
//                cmdMySql.Dispose();
//                if (bWriteLog)
//                    (new Logs()).WriteLogDB(objLog);
//            }
//        }

//        public void ExecuteNonQuery(SqlCommand cmdSql)
//        {
//            MySqlCommand cmdMySql = new MySqlCommand();
//            LogDBEO objLog = new LogDBEO(cmdSql, sConnectionStrings, ConstEx.Log_iType.DATABASE_INSERT_UPDATE_DELETE);
//            try
//            {
//                Convert_SqlCommand_MySqlCommand(cmdSql, ref cmdMySql);
//                cmdMySql.ExecuteNonQuery();
//                objLog.bStatus = true;
//            }
//            finally
//            {
//                cmdMySql.Connection.Close();
//                cmdMySql.Dispose();
//                if (bWriteLog)
//                    (new Logs()).WriteLogDB(objLog);
//            }
//        }

//        public object ExecuteScalar(SqlCommand cmdSql)
//        {
//            MySqlCommand cmdMySql = new MySqlCommand();
//            LogDBEO objLog = new LogDBEO(cmdSql, sConnectionStrings, ConstEx.Log_iType.DATABASE_OTHER);
//            try
//            {
//                Convert_SqlCommand_MySqlCommand(cmdSql, ref cmdMySql);
//                objLog.bStatus = true;
//                return cmdMySql.ExecuteScalar();
//            }
//            finally
//            {
//                cmdMySql.Connection.Close();
//                cmdMySql.Dispose();
//                if (bWriteLog)
//                    (new Logs()).WriteLogDB(objLog);
//            }
//        }
//        #endregion
//    }
//}
////public int DBSize()
////{
////    using (MySqlCommand cmd = new MySqlCommand("select sum(size) * 8 * 1024 from sysfiles"))
////    {
////        cmd.CommandType = CommandType.Text;
////        return (int)ExecuteScalar(cmd);
////    }
////}

////public DataTable getDatabaseSizeCurrent(String _DATABASE_NAME)
////{
////    DataTable dt = new DataTable();
////    MySqlCommand cmd = new MySqlCommand("getDatabaseSizeCurrent", connMySql);
////    cmd.CommandType = CommandType.StoredProcedure;
////    cmd.Parameters.Add(new SqlParameter("@DATABASE_NAME", _DATABASE_NAME));
////    return GetDataTable(cmd);
////}

////public bool CheckConnect()
////{
////    MySqlCommand cmd = new MySqlCommand("select getdate()");
////    if (DataTableEx.DataTable_OK(GetDataTable(cmd)))
////        return true;
////    else
////        return false;
////}

////public Boolean Backup_Database(String LinkBackup)
////{
////    MySqlCommand cmd = new MySqlCommand("BACKUP DATABASE [NguyenManhThang] TO DISK='" + LinkBackup + "'", connMySql);
////    ExecuteNonQuery(cmd);
////    return true;
////}

////public Boolean Restore_Database(String LinkRestore)
////{
////    MySqlCommand cmd = new MySqlCommand("USE MASTER RESTORE DATABASE [NguyenManhThang] FROM DISK='" + LinkRestore + "'", connMySql);
////    ExecuteNonQuery(cmd);
////    return true;
////}